﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

using System;
using System.Globalization;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using DesignByContract;
using Majesty_of_Omega.Config;
using Majesty_of_Omega.Model.Report;

namespace Majesty_of_Omega.GUI.ValueConverters
{
    /// <summary>
    /// Converts a <see cref="SitReportPriority" /> from the \Graphics\Ui - Directory to a <see cref="BitmapImage"/>
    /// </summary>
    public class SeverityToImageConverter : UriToImageConverter
    {
        /// <summary>
        /// Converts a ReportPriority from the \Graphics\Ui - Directory to a <see cref="BitmapImage"/>.
        /// A BitmapImage can be attached to the Image.Source Report.
        /// </summary>
        /// <param name="value">Name of the tech icon</param>
        /// <param name="targetType">must be ImageSource</param>
        /// <param name="parameter">currently not used</param>
        /// <param name="culture">currently not used</param>
        /// <returns>Valid BitmapImage</returns>
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Require.IsTrue(value is SitReportPriority);
            Require.AreEqual(typeof(ImageSource), targetType);
            SitReportPriority reportPriority = (SitReportPriority)value;
            string bitmap;
            switch (reportPriority)
            {
                case SitReportPriority.Green:
                    bitmap = "green_hand.png";
                    break;
                case SitReportPriority.Yellow:
                    bitmap = "orange_hand.png";
                    break;
                case SitReportPriority.Red:
                    bitmap = "red_hand.png";
                    break;
                case SitReportPriority.Special:
                    bitmap = "Urgent.png";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            BitmapImage image = LoadBitmapImage(@"\Graphics\UI\" + bitmap);
            return image;
        }
    }
}